#include"Thread.h"
Thread::Thread(ThreadCallback && cb)
:_thid(0)
,isRun(false)
,_cb(std::move(cb))
{}
Thread::~Thread(){cout<<"~Thid"<<endl;}
void Thread::start(){
    pthread_create(&_thid,nullptr,threadFunc,this);
    isRun = true;
}
void* Thread::threadFunc(void*arg){
    Thread* thread = static_cast<Thread*>(arg);
    if(thread){
        cout<<"Thread run"<<endl;
        thread->_cb(); //动态多态
    }
    else
    {
        cout << "pth == nullptr" << endl;
    }
    pthread_exit(nullptr);
}
void Thread::stop(){
    if(isRun){
        int ret = pthread_join(_thid,nullptr);
        if(ret){
            perror("pthread_join");
            return;
        }
        isRun = false;
    }
}